/**
 * Copyright 2007 Luke Pillow
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.orsomethinglikethat.hinge.asgen;

import com.orsomethinglikethat.hinge.apt.APTMetaClass;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.ClassDeclaration;
import com.sun.mirror.declaration.TypeDeclaration;
import com.sun.mirror.util.DeclarationVisitors;
import com.sun.mirror.util.SimpleDeclarationVisitor;

/**
 * @author lpillow
 */
public class AS3ClassAnnotationProcessor implements com.sun.mirror.apt.AnnotationProcessor
{
    private AnnotationProcessorEnvironment env;
    private ActionScriptClassGenerator classGenerator;

    public AS3ClassAnnotationProcessor( AnnotationProcessorEnvironment env, ActionScriptClassGenerator classGenerator )
    {
        this.env = env;
        this.classGenerator = classGenerator;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sun.mirror.apt.AnnotationProcessor#process()
     */
    public void process()
    {
        for ( TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations() )
        {
            typeDecl.accept( DeclarationVisitors.getSourceOrderDeclarationScanner( new AS3ClassVisitor(), DeclarationVisitors.NO_OP ) );
        }
    }

    private class AS3ClassVisitor extends SimpleDeclarationVisitor
    {
        public void visitClassDeclaration( ClassDeclaration classDeclaration )
        {
            classGenerator.generate( APTMetaClass.build( classDeclaration ), env.getOptions().get( AS3ClassAnnotationProcessorFactory.USER_CLASSES ) );
        }
    }

}
